﻿using Abp.Authorization.Users;
using Abp.Domain.Repositories;
using MyCompanyName.AbpZeroTemplate.Authorization.Users;
using MyCompanyName.AbpZeroTemplate.Prm.Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCompanyName.AbpZeroTemplate.Prm.Authorization
{
    public class PermissionService : AbpZeroTemplateDomainServiceBase
    {
        //项目角色权限
        private readonly IRepository<ProjectRoleFunctionActions> _projectRoleFunctionActionsRepository;
        //项目角色文档权限
        private readonly IRepository<ProjectRoleDocmentActions> _projectRoleDocmentActionsRepository;
        //系统角色权限
        private readonly IRepository<SystemRoleFunctionActions> _systemRoleFunctionActionsRepository;
        //系统角色文档权限
        private readonly IRepository<SystemRoleDocmentActions> _systemRoleDocmentActionsRepository;

        private readonly IRepository<User, long> _userRepository;
        private readonly IRepository<ProjectTeam> _projectTeamRepository;

        public PermissionService(
            IRepository<ProjectRoleFunctionActions> projectRoleFunctionActionsRepository,
            IRepository<ProjectRoleDocmentActions> projectRoleDocmentActionsRepository,
            IRepository<SystemRoleFunctionActions> systemRoleFunctionActionsRepository,
            IRepository<SystemRoleDocmentActions> systemRoleDocmentActionsRepository,
            IRepository<User, long> userRepository,
            IRepository<ProjectTeam> projectTeamRepository)
        {
            _projectRoleFunctionActionsRepository = projectRoleFunctionActionsRepository;
            _projectRoleDocmentActionsRepository = projectRoleDocmentActionsRepository;
            _systemRoleFunctionActionsRepository = systemRoleFunctionActionsRepository;
            _systemRoleDocmentActionsRepository = systemRoleDocmentActionsRepository;
            _userRepository = userRepository;
            _projectTeamRepository = projectTeamRepository;
        }





        //public bool HasPermission(long userId, ProjectFunctions action)
        //{

        //    var user = _userRepository.Get(userId);
        //    var roles = new List<int>();
        //    if (user.Roles.Count > 0)
        //    {
        //        roles = user.Roles.Select(x => x.RoleId).ToList();
        //    }
        //    var projectRoles = _projectTeamRepository.GetAll().Where(x => x.UserId == userId).Select(x => x.ProjectRoleId);
        //    var hasPrm = _projectRoleFunctionActionsRepository.GetAll().Where(x => projectRoles.Contains(x.ProjectRoleId) && x.Permission == action).Any();

        //    return true;
        //}





        //public bool HasPermission(long userId, DocmentFunctions action)
        //{
        //    return true;
        //}









    }
}
